package com.ruoyi.market.http.service;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.market.http.AdminHttpUtil;
import com.ruoyi.market.http.model.ApiResponse;
import com.ruoyi.market.http.model.param.EntryAccountParam;
import com.ruoyi.market.http.model.param.GenBillParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MarketApiService {

    @Autowired
    AdminHttpUtil adminHttpUtil;

    public boolean runSpecialPushTask(){
        String uri = "api/admin/task/runSpecialPushTask";

        JSONObject jsonObject = new JSONObject();

        ApiResponse apiResponse = adminHttpUtil.httpReq(uri, jsonObject);
        if (apiResponse.isSuccess){
            return true;
        }
        return false;
    }

    public boolean pushData(List<String> recordIdList){
        String uri = "api/admin/task/runFormPushTask";

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("recordIds", recordIdList);

        ApiResponse apiResponse = adminHttpUtil.httpReq(uri, jsonObject);
        if (apiResponse.isSuccess){
            return true;
        }
        return false;
    }

    /**
     * 机构信息手推
     * @param uid
     * @return
     */
    public AjaxResult specialPushData(String uid, String infoId){
        String uri = "api/admin/specialPush";

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("uid", uid);
        jsonObject.put("infoId", infoId);

        ApiResponse apiResponse = adminHttpUtil.httpReq(uri, jsonObject);
        if (apiResponse.isSuccess){
            return AjaxResult.success();
        }
        return AjaxResult.error(apiResponse.getRespMsg());
    }

    /**
     * 创建 联登渠道信息
     * @param channelCode
     * @return
     */
    public boolean createChannelUnion(String channelCode){
        String uri = "api/admin/createChannelUnion";

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("channelCode", channelCode);

        ApiResponse apiResponse = adminHttpUtil.httpReq(uri, jsonObject);
        if (apiResponse.isSuccess){
            return true;
        }
        return false;
    }

    /**
     * 更新账单
     */
    public boolean accountGenBillInfo(GenBillParam genBillParam){
        String uri = "api/admin/account/genBill";

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("dateInfo", genBillParam.getDateInfo());
        jsonObject.put("dataId", genBillParam.getDateId());
        jsonObject.put("dataType", genBillParam.getDateType());

        ApiResponse apiResponse = adminHttpUtil.httpReq(uri, jsonObject);
        if (apiResponse.isSuccess){
            return true;
        }
        return false;
    }

    /**
     * 查询api推送结果
     */
    public boolean querySpeApiResult(){
        String uri = "api/admin/querySpeApiResult";

        JSONObject jsonObject = new JSONObject();

        ApiResponse apiResponse = adminHttpUtil.httpReq(uri, jsonObject);
        if (apiResponse.isSuccess){
            return true;
        }
        return false;
    }

    /**
     * 入账申请，进行入账操作
     */
    public AjaxResult entryAccount(EntryAccountParam entryAccountParam){
        String uri = "api/admin/account/entryAccount";

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("recordId", entryAccountParam.getRecordId());
        jsonObject.put("operatorId", entryAccountParam.getOperatorId());
        jsonObject.put("operatorName", entryAccountParam.getOperatorName());

        ApiResponse apiResponse = adminHttpUtil.httpReq(uri, jsonObject);
        if (apiResponse.isSuccess){
            return AjaxResult.success();
        }
        return AjaxResult.error(apiResponse.getRespMsg());
    }

    /**
     * 产品/渠道 每日消耗入账
     */
    public boolean xhApplyEnter(EntryAccountParam entryAccountParam){
        String uri = "api/admin/account/xhApplyEnter";

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("recordId", entryAccountParam.getRecordId());
        jsonObject.put("recordType", entryAccountParam.getRecordType());
        jsonObject.put("operatorId", entryAccountParam.getOperatorId());
        jsonObject.put("operatorName", entryAccountParam.getOperatorName());

        ApiResponse apiResponse = adminHttpUtil.httpReq(uri, jsonObject);
        if (apiResponse.isSuccess){
            return true;
        }
        return false;
    }


    /**
     * 入账申请，进行入账操作
     */
    public boolean testSms(String mobile){
        String uri = "api/admin/testSms";

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("mobile", mobile);

        ApiResponse apiResponse = adminHttpUtil.httpReq(uri, jsonObject);
        if (apiResponse.isSuccess){
            return true;
        }
        return false;
    }



}
